import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../provider/counter.dart';
import '../../provider/cart_bak.dart';
import '../cart/cart_item.dart';
import '../cart/cart_num.dart';

class CartPage extends StatefulWidget {
  CartPage({Key key}) : super(key: key);

  @override
  _CartPageState createState() => _CartPageState();
}

class _CartPageState extends State<CartPage> {
  @override
  Widget build(BuildContext context) {
    
    var counterProvider = Provider.of<Counter>(context);

    return Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            /// 调用自增方法，改变状态
            counterProvider.increment();
            /// 给购物出列表增加数据
            context.read<Cart>().addData('ihone11-${counterProvider.count}');
            
          },
          child: Icon(Icons.add)
        ),
        body: Column(
          children: <Widget>[
            Center(
              child: Text('统计数量：${counterProvider.count}', 
                style: TextStyle(
                  fontSize: 20
                )
              )  
            ),
            Divider(),

            // 加载购物车列表的子组件
            //CartItem(),
            Divider(height: 40),
            //CartNum()

          ]
        )
      
      );
  }
}